const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
const _ = db.command;

exports.main = async (event, context) => {

  const wxContext = cloud.getWXContext()
  
  const user = await db.collection("user").where({
    openid:wxContext.OPENID,
  }).get()
  if(user.data.length == 0)
  {
    return {
      code:401,
      data:{},
      msg:"have not login"
   }
  }

  const result = await db.collection("notice").get()
  return {
    result:result.data[0].message,
    msg:"success"
  }
};
